package com.base.caselib.presenter;

import android.app.Activity;

import com.base.caselib.bean.CaseListModel;
import com.base.caselib.view.CaseListAjView;
import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;

import java.util.HashMap;

import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2019/11/28.
 */

public class CaseListAjPresenter extends BasePresenter<CaseListAjView> {
    public CaseListAjPresenter(CaseListAjView view, Activity activity) {
        super(view, activity);
    }



    public void getCaseList(final Integer index, String keyWord, String ids){
        HashMap<String, Object> params = new HashMap<>();
        params.put("page", index);
        params.put("limit",15);
        params.put("caseStatus","");
        //初始化控件
        Disposable disposable = RealNetWorkUtil.postContent()
                .content(params)
                .method("api-safety/tCaseInfo/getList")
                .build().enqueue(CaseListModel.class, new CallBackImpl<CaseListModel>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnError();

                    }
                    @Override
                    public void onNext(CaseListModel list) {
                        if (index==1){
                            //刷新
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnList(list.getRows());
                            }else {
                                mView.returnNoData();
                            }
                        }else {
                            //更多
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnMoreList(list.getRows());
                            }else {
                                mView.returnNoMoreData();
                            }
                        }
                    }
                });
        mCompositeDisposable.add(disposable);
    }
}
